<?php
include("../functions.php");
include("../libs/smarty.class.php");

$smarty = new Smarty();
$title = "Praktyki studenckie do zaakceptowania";
$smarty->assign("title",$title);

$accept_id = $_GET['p_id'];
if($accept_id != ''){
    $practice_id = $accept_id;
    $student_id = $_GET['s_id'];
    $delete_id = $_GET['d_id'];
    $query = mysql_query("UPDATE user_student SET practice_id = '$practice_id' WHERE id = '$student_id'");
    $query2 = mysql_query("DELETE FROM `student_practices_queue` WHERE id='$delete_id'");
    $info_action = getInfo(15);
    $info_color = "green";
}

$delete_id = $_GET['delete_id'];
if($delete_id !=''){
    $query = mysql_query("DELETE FROM `student_practices_queue` WHERE id='$delete_id'");
    $info_action = getInfo(16);
    $info_color = "red";
}

$query = mysql_query("SELECT
  user_student.surname AS student_surname,
  user_student.name AS student_name,
  user_student.email AS student_email,
  user_company.name,
  user_company.email,
  student_practices_queue.practice_id,
  student_practices_queue.student_id,
  student_practices_queue.id
FROM
  student_practices_queue
  INNER JOIN practices ON (student_practices_queue.practice_id = practices.id)
  INNER JOIN user_student ON (student_practices_queue.student_id = user_student.id)
  INNER JOIN user_company ON (practices.company_id = user_company.id)");

$practice_queue = array();
while($row = mysql_fetch_assoc($query)){
    $practice_queue[] = $row;
}

$smarty->assign("info_action",$info_action);
$smarty->assign("info_color",$info_color);
$smarty->assign("practice_queue",$practice_queue);
$smarty->display('student_practices.tpl');
?>
